package messages;

import java.io.IOException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import utils.Serialization;
import utils.XmlSerializationUtils;
import connection.exception.ConnectionResetException;

public class SignatureValidationResponseMessage implements Convertible {

    private static final long serialVersionUID = 1L;

    public Integer _signatureSerial;
    
    public Boolean _result;

    public SignatureValidationResponseMessage() {}
    
    public SignatureValidationResponseMessage(Integer sigSerial, Boolean result) {
        _signatureSerial = sigSerial;
        _result = result;
    }
    
    @Override
    public Element convertToCanonic(Document doc) {
        
        String className = getClass().getSimpleName();
        
        Element el = doc.createElement(className);

        Element childEl2 = doc.createElement("SignatureSerial");
        childEl2.setTextContent(_signatureSerial.toString());
        el.appendChild(childEl2);
        
        if (_result != null) {
            Element childEl = doc.createElement("Result");
            childEl.setTextContent(_result.toString());
            el.appendChild(childEl);
        }  

        return el;
    } 


    @Override
    public Object convertFromCanonic(Element el) {
        this._signatureSerial = XmlSerializationUtils.getIntValue(el, "SignatureSerial");
        this._result = new Boolean(XmlSerializationUtils.getTextValue(el, "Result"));
        return this;
    }

    public static void main(String[] args) throws ConnectionResetException, IOException{

        SignatureValidationResponseMessage gen = new SignatureValidationResponseMessage();
        gen._signatureSerial = 1233355;
        gen._result = false;

        byte[] serialized = Serialization.Serialize(gen);

        Object newGen = Serialization.Deserialize(serialized);

        newGen.toString();

        System.in.read();
    }
}

